@extends('layouts.back_stage')
@section('content')
    <link rel="stylesheet" href="{{env('CDN_DOMAIN_NAME')}}/css/dispersionCodeDetails.css">
    <link rel="stylesheet" href="{{env('CDN_DOMAIN_NAME')}}/css/commoncss/select2.min.css">
    <style>
        @media print {
            .TreeTable {display: block !important;}
            .TreeInfo{display: block !important;}
            .h3Info{display: block !important;}
        }
        @media screen {
            .TreeTable {display: none !important;}
            .TreeInfo{display: none !important;}
            .h3Info{display: none !important;}
        }
        .model_box {position: fixed !important;  top: 0;left: 0;}
    </style>
    <div class="container">
        <audio id="music_success" src="{{env('CDN_DOMAIN_NAME')}}/store/mp3/success.mp3" type="audio/mp3"></audio>
        <audio id="music_faile" src="{{env('CDN_DOMAIN_NAME')}}/store/mp3/faile.mp3" type="audio/mp3"></audio>
        <div style="padding:20px 0;"><h3>单店配货详情</h3>
        </div>
        <div style="float: right">
            @if($data->status == 0)
                <button class="btn btn-info successDistribution" onclick="showModel()" abc="2">完成配货</button>
            @endif
            @if($data->status == 1)
                <button class="btn btn-info successDistribution" onclick="reStart()" abc="2">重新开启</button>
                <button class="btn btn-info successPrint" onclick="preview()">打印配货单</button>
                <button class="btn btn-info successPrint" onclick="TreeDan()">打印三联单</button>
            @endif
            @if($data->status == 2)
                <button class="btn btn-info successPrint" onclick="preview()">打印配货单</button>
                <button class="btn btn-info successPrint" onclick="TreeDan()">打印三联单</button>
            @endif
        </div>
        @if($data->status == 0)
        <div class="search_box" style="margin-bottom: 10px;">
            <label>扫描条码：</label>
            <input type="text" class="form-control scan_qr" placeholder="请扫描条码">
        </div>
        @endif
        <div class="search_box">
            <label>搜索款号：</label>
            <input type="text " class="form-control serach_girard" placeholder="请输入款号" id="">
            <input type="text " class="form-control serach_code" placeholder="请输入服装编号" id="">
            <button class="btn btn-success serach">搜索</button>
            <button class="btn btn-info" onclick="reSetSearch()">重置</button>
        </div>

        <!--startTreePrint-->
        <style>
            .TreeTable > thead > tr > th, .TreeTable > tbody > tr > th, .TreeTable > tfoot > tr > th, .TreeTable > thead > tr > td, .TreeTable > tbody > tr > td, .TreeTable > tfoot > tr > td{padding:4px 8px;}
            .table-bordered > thead > tr > th, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > tbody > tr > td, .table-bordered > tfoot > tr > td{border: 1px solid #000;}
            .TreeTable > thead > tr > th, .TreeTable > tbody > tr > th, .TreeTable > tfoot > tr > th, .TreeTable > thead > tr > td, .TreeTable > tbody > tr > td, .TreeTable > tfoot > tr > td{border: 1px solid #000;}
            .TreeInfo > thead > tr > th, .TreeInfo > tbody > tr > th, .TreeInfo > tfoot > tr > th, .TreeInfo > thead > tr > td, .TreeInfo > tbody > tr > td, .TreeInfo > tfoot > tr > td{padding:2px 8px;}
            .TreeInfo{margin-top:10px;}
        </style>
        <h3 class="h3Info" style="width:100%;height:30px;text-align:center;font-size:20px;">批发销售单</h3>
        <table class="table table-bordered TreeTable" border="1" bordercolor="#000000" style="border-collapse:collapse;" style="margin-bottom:0;">
            <tr class="text-center">
                <td rowspan="4" style="vertical-align:middle;text-align:center;">款号</td>
                <td rowspan="4" style="vertical-align:middle;text-align:center;">颜色</td>
                <td rowspan="4" style="vertical-align:middle;text-align:center;">吊牌价/元</td>
                <td>鞋子</td>
                <td class="text-center">26</td>
                <td class="text-center">27</td>
                <td class="text-center">28</td>
                <td class="text-center">29</td>
                <td class="text-center">30</td>
                <td class="text-center">31</td>
                <td class="text-center">32</td>
                <td class="text-center">33</td>
                <td class="text-center">34</td>
                <td class="text-center">35</td>
                <td class="text-center">36</td>
                <td class="text-center">37</td>
                <td rowspan="4" style="vertical-align:middle;">合计</td>
            </tr>
            {{--<tr class="text-center">--}}
                {{--<td>大人鞋帽</td>--}}
                {{--<td class="text-center">35</td>--}}
                {{--<td class="text-center">36</td>--}}
                {{--<td class="text-center">37</td>--}}
                {{--<td class="text-center">38</td>--}}
                {{--<td class="text-center">39</td>--}}
                {{--<td class="text-center">40</td>--}}
                {{--<td class="text-center">41</td>--}}
                {{--<td class="text-center">42</td>--}}
                {{--<td class="text-center">43</td>--}}
                {{--<td class="text-center">44</td>--}}
                {{--<td class="text-center">-</td>--}}
                {{--<td class="text-center">-</td>--}}
            {{--</tr>--}}
            <tr class="text-center">
                <td>服装</td>
                <td class="text-center">5</td>
                <td class="text-center">7</td>
                <td class="text-center">9</td>
                <td class="text-center">11</td>
                <td class="text-center">13</td>
                <td class="text-center">15</td>
                <td class="text-center">17</td>
                <td class="text-center">19</td>
                <td class="text-center">21</td>
                <td class="text-center">-</td>
                <td class="text-center">-</td>
                <td class="text-center">-</td>
            </tr>
            <tr class="text-center">
                <td>小童服饰</td>
                <td class="text-center">80</td>
                <td class="text-center">86</td>
                <td class="text-center">92</td>
                <td class="text-center">98</td>
                <td class="text-center">104</td>
                <td class="text-center">110</td>
                <td class="text-center">-</td>
                <td class="text-center">-</td>
                <td class="text-center">-</td>
                <td class="text-center">-</td>
                <td class="text-center">-</td>
                <td class="text-center">-</td>
            </tr>
            <tr class="text-center">
                <td>配饰</td>
                <td class="text-center">S</td>
                <td class="text-center">M</td>
                <td class="text-center">L</td>
                <td class="text-center">XS</td>
                <td class="text-center">XL</td>
                <td class="text-center">F</td>
                <td class="text-center">-</td>
                <td class="text-center">-</td>
                <td class="text-center">-</td>
                <td class="text-center">-</td>
                <td class="text-center">-</td>
                <td class="text-center">-</td>
            </tr>
            <?php $total_price = $size_1 = $size_2 = $size_3 = $size_4 = $size_5 = $size_6 = $size_7
                = $size_8 = $size_9 = $size_10 = $size_11 = $size_12 = $size_13 = 0;?>
            @if(count($triple_orders))
                @foreach($triple_orders as $k => $v)
                    <tr>
                        <td>{{$v['girard']}}</td>
                        <td>{{$v['color']}}</td>
                        <td>{{$v['price']}}</td>
                        <td class="text-center">
                            @if(array_intersect([26,27,28,29,30,31,32,33,34,35,36,37],$v['sizes']))
                                鞋子
                            @elseif(array_intersect([5,7,9,11,13,15,17,19,21],$v['sizes']))
                                服装
                            @elseif(array_intersect([80,86,92,98,104,110],$v['sizes']))
                                小童服饰
                            @elseif(array_intersect(['S','M','L','XS','XL','F'],$v['sizes']))
                                配饰
                            @else
                                -
                            @endif
                        </td>
                        <td class="text-center">{{$v['size1']}}</td>
                        <td class="text-center">{{$v['size2']}}</td>
                        <td class="text-center">{{$v['size3']}}</td>
                        <td class="text-center">{{$v['size4']}}</td>
                        <td class="text-center">{{$v['size5']}}</td>
                        <td class="text-center">{{$v['size6']}}</td>
                        <td class="text-center">{{$v['size7']}}</td>
                        <td class="text-center">{{$v['size8']}}</td>
                        <td class="text-center">{{$v['size9']}}</td>
                        <td class="text-center">{{$v['size10']}}</td>
                        <td class="text-center">{{$v['size11']}}</td>
                        <td class="text-center">{{$v['size12']}}</td>
                        <td class="text-center" style="color:red;">{{$v['stock_sum']}}</td>
                    </tr>
                    <?php
                    $size_1 += intval($v['size1']);
                    $size_2 += intval($v['size2']);
                    $size_3 += intval($v['size3']);
                    $size_4 += intval($v['size4']);
                    $size_5 += intval($v['size5']);
                    $size_6 += intval($v['size6']);
                    $size_7 += intval($v['size7']);
                    $size_8 += intval($v['size8']);
                    $size_9 += intval($v['size9']);
                    $size_10 += intval($v['size10']);
                    $size_11 += intval($v['size11']);
                    $size_12 += intval($v['size12']);
                    $size_13 += intval($v['stock_sum']);
                    $total_price +=$v['price']*$v['stock_sum'];
                    ?>
                @endforeach
            @endif
            <tr>
                <td colspan="3">总合计</td>
                <td class="text-center">-</td>
                <td class="text-center" style="color:red;">{{$size_1 ?: ''}}</td>
                <td class="text-center" style="color:red;">{{$size_2 ?: ''}}</td>
                <td class="text-center" style="color:red;">{{$size_3 ?: ''}}</td>
                <td class="text-center" style="color:red;">{{$size_4 ?: ''}}</td>
                <td class="text-center" style="color:red;">{{$size_5 ?: ''}}</td>
                <td class="text-center" style="color:red;">{{$size_6 ?: ''}}</td>
                <td class="text-center" style="color:red;">{{$size_7 ?: ''}}</td>
                <td class="text-center" style="color:red;">{{$size_8 ?: ''}}</td>
                <td class="text-center" style="color:red;">{{$size_9 ?: ''}}</td>
                <td class="text-center" style="color:red;">{{$size_10 ?: ''}}</td>
                <td class="text-center" style="color:red;">{{$size_11 ?: ''}}</td>
                <td class="text-center" style="color:red;">{{$size_12 ?: ''}}</td>
                <td class="text-center" style="color:red;">{{$size_13 ?: ''}}</td>
            </tr>
        </table>
        <table class="table table-hover TreeInfo">
            <tr>
                <th class="col-sm-1" style="border-top:none;">总价：{{$total_price}}元</th>
                <th class="col-sm-1" style="border-top:none;">折扣：__________</th>
                <th class="col-sm-1" style="border-top:none;">折扣总价：____________________</th>
            </tr>
            <tr>
                <th class="col-sm-1" style="border-top:none;">店铺：{{ $data->shop_name }}</th>
                <th class="col-sm-1" style="border-top:none;">日期：{{ $data->success_at }}</th>
                <th class="col-sm-1" style="border-top:none;">联系方式：{{ $data->tel }}</th>
            </tr>
            <tr>
                <th class="col-sm-1" style="border-top:none;">操作员：{{ $data->user_name }}</th>
                <th class="col-sm-1" style="border-top:none;">重量： @if(!empty($data->weight)) {{$data->weight}} kg @else - @endif </th>
                <th class="col-sm-1" style="border-top:none;">快递单号：{{$data->express_num or '-'}}</th>
            </tr>
            <tr>
                <th class="col-sm-1" style="border-top:none;">备注：{{ $data->comment or '-' }}</th>
                <th class="col-sm-1" style="border-top:none;"></th>
                <th class="col-sm-1" style="border-top:none;"></th>
            </tr>
        </table>
        <!--endTreePrint-->


        <!--startprint-->
        <p class="success_info">店铺：{{ $data->shop_name }}
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;日期：{{ $data->success_at }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;操作员：{{ $data->user_name }}
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;联系方式：{{ $data->tel }}</p>
        <p class="comment_sp">
            备注：{{ $data->comment }}
        </p>
        <p>总计：<span class="sum_count">0</span>件</p>
        <p class="weight_sp">
            重量：{{ $data->weight }}kg
        </p>
        <p>快递单号：{{$data->express_num}}</p>


        <h3 class="table-sum-text">汇总</h3>
        <table class="table table-hover table-sum">
            <thead>
            <tr>
                <th class="col-sm-1">序号</th>
                <th class="col-sm-1">款号</th>
                <th class="col-sm-1">颜色</th>
                <th class="col-sm-1">数量</th>
            </tr>
            </thead>
            <tbody>

            </tbody>
        </table>
        <h3 class="table-info-text">详情</h3>
        <table class="table table-hover table-info">
            <thead>
            <tr>
                <th class="col-sm-1">序号</th>
                <th class="col-sm-1">款号</th>
                <th class="col-sm-1">服装编号</th>
                <th class="col-sm-1">颜色</th>
                <th class="col-sm-1">尺码</th>
                <th class="col-sm-1">价格(元)</th>
                <th class="col-sm-1">录入时间</th>
                @if($data->status == 0)
                    <th class="col-sm-1">操作</th>
                @endif
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <!--endprint-->


        <table class="table table-hover table-search">
            <thead>
            <tr>
                <th class="col-sm-1">序号</th>
                <th class="col-sm-1">款号</th>
                <th class="col-sm-1">服装编号</th>
                <th class="col-sm-1">颜色</th>
                <th class="col-sm-1">尺码</th>
                <th class="col-sm-1">价格(元)</th>
                <th class="col-sm-1">录入时间</th>
                @if($data->status == 0)
                    <th class="col-sm-1">操作</th>
                @endif
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <div class="model_box">
            <div class="model">
                <p>完成配货</p>
                <div style="width:100%;margin-bottom:10px;">
                    <label>备注</label>
                    <input type="text" class="form-control order-comment" value="">
                </div>
                <div style="width:100%;margin-bottom:10px;">
                    <label class="text-weight">重量</label>
                    <div class="input-group">
                        <input type="text" class="form-control order-weight" value="">
                        <div class="input-group-addon">kg</div>
                    </div>
                </div>
                <button class="btn btn-info model-check" style="margin-left:50px;margin-top:15px;">确定</button>
                <button class="btn btn-info model-cancel" style="margin-left:90px;margin-top:15px;" onclick="removeModel()">取消</button>

            </div>
        </div>
    </div>
    <script src="{{env('CDN_DOMAIN_NAME')}}/js/commonjs/select2.min.js"></script>
    <script type="text/javascript">
        var dragger;
        var globarStatus = {{ $data->status }};
        var bill_id = {{ $bill_id }};
        var domain_name = '{{ env('DOMAIN_NAME') }}';
        var pipeline = '{{ $data->assembly_num }}'
    </script>
    <script src="{{env('CDN_DOMAIN_NAME')}}/js/dispersionCodeDetails.js?v0.0.5"></script>
    <script type="text/javascript">
        $('.scan_qr').bind('keyup', function (event) {
            if (event.keyCode == '13') {
                // $('.scan_qr').val().replace(/\s+/g,'')
                var qr_code = $('.scan_qr').val().replace(/\s+/g,"")
                // console.log(qr_code.length,qr_code.replace(/\s+/g,'').length)
                if (qr_code.length >= 14 && qr_code.length <= 16) {
                    $.ajax({
                        headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                        url: '/pipeline/check',
                        type: 'post',
                        data: {
                            code: qr_code,
                            total_num: 0,
                            sort_nu: 0,
                            assembly_num: pipeline,
                            release: 1,
                            type: 2,
                        },
                        dataType: 'json',
                        success: function (res) {
                            if (res.result.success == true) {
                                $('.scan_qr').select()
                            } else {
                                var music = document.getElementById("music_faile");
                                music.play()
                                $('.scan_qr').select()
                                $(".faceImg").attr("src", "/img/weep.png");
                                $(".oHandle").text(res.result.errorMsg);
                                $(".oSuccess").show(0).delay(3000).hide(0);
                            }
                        },
                        error: function () {
                        }
                    });
                }
            }
        })

        function TreeDan() {
            var bdhtml = window.document.body.innerHTML; //获取当前页的html代码
            var startStr = "<!--startTreePrint-->"; //设置打印开始区域
            var endStr = "<!--endTreePrint-->"; //设置打印结束区域
            var printHtml = bdhtml.substring(bdhtml.indexOf(startStr) + startStr.length, bdhtml.indexOf(endStr)); //从标记里获取需要打印的页面
            window.document.body.innerHTML = printHtml; //需要打印的页面
            window.print();
            window.document.body.innerHTML = bdhtml; //还原界面
        }
    </script>
@endsection